<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iRoomMonitor Mobile</title>
<!-- IE8 compatability fix -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<!-- the 'link' method for css inclusion is supported by most browsers -->
<link type="text/css" href="../reset.css" rel="stylesheet" />
<link type="text/css" href="style_mobile.css" rel="stylesheet" />
<?php
	session_start();
	// Store username in variable
	$name = $_SESSION["username"];
	// Only support Royal Panda theme!
	$theme = "../style_royal_panda.css";
	echo '<link type="text/css" href="'.$theme.'" rel="stylesheet" />';
?>
</head>

<?php
	// MySQL connection information
	include_once("/var/mysql/mysql_connect.php");
	// Include the useful functions
	include_once("../functions.php");
	// Construct the whitelist of approved pages the user may visit
	$whitelist = array("login");
	$isLoggedIn = false;
	if($_GET['p'] == "" || !isset($_GET['p'])){
		header("Location:?p=login");
		$_GET["p"] = "login";
	}
	// Append any pages that are available for logged in users
	if(isset($_SESSION["loggedIn"]))
	{
		include_once("functions.php");
		// Add logged in available pages
	 	$whitelist[] = "home";
	}
?>

<body>
<div id="wrap">
  <div id="header"><h1>iRoomMonitor Mobile</h1></div>
	<div id="container">
		<div id="main">
			<?php 
				if(isset($_GET["p"]) && in_array($_GET["p"],$whitelist))
				{
					include($_GET["p"].".php");
				}
				else
				{
					// Default to home if unapproved page visit
					if(isset($_SESSION['loggedIn']))
						header("Location:?p=home");
					else
						header("Location:?p=login");
				}
			?>
		</div>
	</div>
  <div id="footer">
  	<?php include("footer.php"); ?>
  </div>
</div>
</body>

<?php
	mysqli_close($database);
?>
</html>
